<?php
	require_once(dirname(__FILE__) . '/../../lib/PageLayout.php');
	require_once(dirname(__FILE__) . '/../../lib/MarketDB.php');
	
	// Instance a new Database
	$marketDB = new MarketDB();

	$day = date("j", time()); $month = date("n", time()); $year = date("Y", time());
	$today = mktime(0,0,0, $month, $day, $year);
	$yesterday = mktime(0,0,0, $month, $day-1, $year);
	$lastweek = mktime(0,0,0, $month, $day-7, $year);

	$title="";
	$headings = array(" ", "Auctions", "Value", "Average","Highest","Return");
	$align = array("center","center","right","right","center","right");
	$bestSellers = array();
	$auctions = array();
	$auctions[] = $marketDB->getSalesDataByDay($today);
	$auctions[] = $marketDB->getSalesDataByDay($yesterday, $today);
	$auctions[] = $marketDB->getSalesDataByDay($lastweek);
	$bestSellers[] = $marketDB->getHighestSales($today);
	$bestSellers[] = $marketDB->getHighestSales($yesterday, 1,  $today);
	$bestSellers[] = $marketDB->getHighestSales($lastweek);
	$data = array();
	foreach($bestSellers as $key => $val) {
		$bestSellers[$key]['name'] = str_replace("Scroll of Enchant", "SOE", $bestSellers[$key]['name']);
	}
	$data[] = array("Today", $auctions[0]['count'], getGold($auctions[0]['sum']), getGold($auctions[0]['avg']), "<a href='#limit=7&id={$bestSellers[0]['itemid']}' onClick='showSales(7, {$bestSellers[0]['itemid']})'>" . $bestSellers[0]['name'] . "</a>", getGold($bestSellers[0]['sum']));
	$data[] = array("Yesterday", $auctions[1]['count'], getGold($auctions[1]['sum']), getGold($auctions[1]['avg']), "<a href='#limit=7&id={$bestSellers[1]['itemid']}' onClick='showSales(7, {$bestSellers[1]['itemid']})'>" . $bestSellers[1]['name'] . "</a>", getGold($bestSellers[1]['sum']));
	$data[] = array("This Week", $auctions[2]['count'], getGold($auctions[2]['sum']), getGold($auctions[2]['avg']), "<a href='#limit=7&id={$bestSellers[2]['itemid']}' onClick='showSales(7, {$bestSellers[2]['itemid']})'>" . $bestSellers[2]['name'] . "</a>", getGold($bestSellers[2]['sum']));

	$top = new Table($title, $data, $headings);
	$top->setPadding(2);
	$top->setMargin(0, 'bottom');
	$top->setStyle("padding: 0px");
	$top->setStyle("width: 650px;");
	$top->setAlign($align);
	
	
	echo '<div style="text-align:center; color: white; font-size: 1.375em; font-style:italic; margin-bottom:3px;">' . $marketDB->getServerName() . '</div>';
	$top->printTable();
	unset($marketDB);
?>